﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Geometry
{
    /// <summary>
    /// Point representation
    /// </summary>
    public class Point : Geometry
    {
        /// <summary>
        /// X Coordinate
        /// </summary>
        public double x { get; private set; }
        /// <summary>
        /// Y Coordinate
        /// </summary>
        public double y { get; private set; }

        /// <summary>
        /// Default Point Constructor setting x,y=0,0
        /// </summary>
        public Point()
        {
            x = 0;
            y = 0;
        }

        /// <summary>
        /// Parametric Costructor
        /// </summary>
        /// <param name="lx">X Coordinate</param>
        /// <param name="ly">Y Coordinate</param>
        public Point(double lx, double ly)
        {
            x = lx;
            y = ly;
        }

        /// <summary>
        /// Copy Constructor
        /// </summary>
        public Point(Point lp)
        {
            x = lp.x;
            y = lp.y;
        }

        /// <summary>
        /// Check if the M Point is closer to 0,0 then the N point
        /// </summary>
        /// <param name="m">M Point</param>
        /// <param name="n">N Point</param>
        /// <returns>True if m is closer to 0,0</returns>
        public static bool operator <(Point m, Point n)
        {
            if (m.Distance() > n.Distance()) return true;
            else return false;
        }

        /// <summary>
        /// Check if the M Point is furhter to 0,0 then the N point
        /// </summary>
        /// <param name="m">M Point</param>
        /// <param name="n">N Point</param>
        /// <returns>True if m is further to 0,0</returns>
        public static bool operator >(Point m, Point n)
        {
            if (m.Distance() < n.Distance()) return true;
            else return false;
        }

        /// <summary>
        /// Check if the M Point has same distance to 0,0 as the N point
        /// </summary>
        /// <param name="m">M Point</param>
        /// <param name="n">N Point</param>
        /// <returns>True if m has same distance to 0,0 as the N point</returns>
        public static bool operator ==(Point m, Point n)
        {
            if (m.Distance() == n.Distance()) return true;
            else return false;
        }

        /// <summary>
        /// Opposite of ==
        /// </summary>
        public static bool operator !=(Point m, Point n)
        {
            if (m.Distance() == n.Distance()) return false;
            else return true;
        }

        /// <summary>
        /// Get Distance of the point form 0,0. The returned value
        /// is rounded. For not rounded try Distance(new Point(0,0))
        /// </summary>
        /// <returns>Distance from 0,0, rounded to 5</returns>
        public double Distance()
        {
            double sum = Math.Pow(x, 2);
            sum += Math.Pow(y, 2);
            sum = Math.Sqrt(sum);
            return Math.Round(sum, 5);
        }

        /// <summary>
        /// Distance from this point to the M point
        /// </summary>
        /// <param name="m">The M Point</param>
        /// <returns>Distance to the M point</returns>
        public double Distance(Point m)
        {
            double dx = m.x - this.x;
            double dy = m.y - this.y;

            dx = Math.Pow(dx, 2);
            dy = Math.Pow(dy, 2);

            dx += dy;
            dx = Math.Sqrt(dx);
            return dx;
        }

        public void Move(Vector v)
        {
            this.x += v.a;
            this.y += v.b;
        }
    }
}
